//
//  UIImage+Clip.m
//  RM_IM
//
//  Created by zhangzhenyun on 2018/7/21.
//  Copyright © 2018年 user1. All rights reserved.
//

#import "UIImage+Clip.h"

@implementation UIImage (Clip)

+ (UIImage *)clipCircleImageWithImage:(UIImage *)image rect:(CGRect)rect {
    //1、开启上下文
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
    //2、设置裁剪区域
    UIBezierPath * path = [UIBezierPath bezierPathWithOvalInRect:rect];
    [path addClip];
    //3、绘制图片
    [image drawAtPoint:CGPointZero];
    //4、获取新图片
    UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
    //5、关闭上下文
    UIGraphicsEndImageContext();

    //6、返回新图片
    return newImage;
    
}
@end
